package ${codeModel.packageName};

<#list importList?keys as key>
import ${importList[key]};
</#list>	

/**
 * @description service接口实现类${tableClassModel.tableMemo}
 * @author ${dataSource.author}
 * @date ${time}
 */
@Service
public class  ${ClassName} implements  ${serviceInterface}{

	
	@Autowired
	private ${daoClassName} ${daoVariableName};
	
	
	@Override
	public int add(${tableClassModel.className} ${tableClassModel.classVariableName}){
		// 设置基本字段信息
		SysUsers loginUser = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
		${tableClassModel.classVariableName}.setCreateBy(loginUser.getSuName());
		${tableClassModel.classVariableName}.setUpdateBy(loginUser.getSuName());
		${tableClassModel.classVariableName}.set${tableClassModel.primaryKey.methodName}(UUIDUtil.getRandomID());
		return ${daoVariableName}.insert(${tableClassModel.classVariableName});
		
	}
	
	@Override
	public int batchAdd(List<${tableClassModel.className}>  ${tableClassModel.classVariableName}List) {
		//这里没有做基本字段的设置，如有需要请自己实现	
		int num = 0;
		int c = 10000;
		int size = ${tableClassModel.classVariableName}List.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= ${tableClassModel.classVariableName}List.size() ? ${tableClassModel.classVariableName}List.size() : end;
			List<${tableClassModel.className}> insertList = ${tableClassModel.classVariableName}List.subList(begin, end);
			num += ${daoVariableName}.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(${tableClassModel.className} old${tableClassModel.className}
	,${tableClassModel.className} new${tableClassModel.className}){
	
		Map<String, Object> modifyMap = null;
		try {
			if (!ModelUtils.isModified(old${tableClassModel.className}, new${tableClassModel.className})) {
				return MatrixConstance.DML_SUCCESSS;
			}
			modifyMap = ModelUtils.comparePojo2Map(old${tableClassModel.className}, new${tableClassModel.className});
		} catch (Exception e) {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, new${tableClassModel.className});
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("${tableClassModel.primaryKey.property}", old${tableClassModel.className}.get${tableClassModel.primaryKey.methodName}());
			${daoVariableName}.updateByMap(modifyMap);
		}
		return MatrixConstance.DML_SUCCESSS;
	}
	
	@Override
	public int modifyByModel(${tableClassModel.className} ${tableClassModel.classVariableName}){
	
		return ${daoVariableName}.updateByModel(${tableClassModel.classVariableName});
	
	}
	
	
	
	@Override
	public int remove(List<${tableClassModel.primaryKey.classType}> list){
	
		return ${daoVariableName}.deleteByIds(list);
	
	}

	@Override
	public int removeById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}){
	
		return ${daoVariableName}.deleteById(${tableClassModel.primaryKey.property});
	
	}
	
	@Override
	public int removeByModel(${tableClassModel.className} ${tableClassModel.classVariableName}){
	
		return ${daoVariableName}.deleteByModel(${tableClassModel.classVariableName});
	
	}
	
	
	@Override
	public List<${tableClassModel.className}> findInPage(${tableClassModel.className} ${tableClassModel.classVariableName},  PaginationVO pageVo){
	
		return ${daoVariableName}.selectInPage(${tableClassModel.classVariableName} , pageVo);
	
	}
	
	@Override
	public List<${tableClassModel.className}> findByModel(${tableClassModel.className} ${tableClassModel.classVariableName}){
	
		return ${daoVariableName}.selectByModel(${tableClassModel.classVariableName});
	
	}
	
	@Override
	public int  findTotal(${tableClassModel.className} ${tableClassModel.classVariableName}){
	
		return ${daoVariableName}.selectTotalRecord(${tableClassModel.classVariableName});
	
	}
	
	@Override
	public ${tableClassModel.className}  findById(${tableClassModel.primaryKey.classType} ${tableClassModel.primaryKey.property}){
	
		return ${daoVariableName}.selectById(${tableClassModel.primaryKey.property});
	
	}

   	
	
	
}